import Vue from 'vue'
import Vuex from 'vuex'
import persist from "vuex-persist"
Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    shopadd: [],
  },
  mutations: {
    add(state, item) {
      var flag = false;
      state.shopadd.forEach((res) => {
        if (item.cid == res.cid) {
          res.num++;
          flag = true;
        }
      })
      if (flag == false) {
        Vue.set(item, 'num', 1)
        state.shopadd.push(item)
      }
    },
    del(state, item) {
      console.log(item)
      state.shopadd.forEach((res, index) => {
        if (res.cid == item.cid) {
          state.shopadd.splice(index, 1)
        }
      });
    },
    // 调用步进器change事件
    num() {}
  },
  actions: {},
  modules: {},
  plugins: [
    new persist({
      storage: window.localStorage,
    }).plugin,
  ],
})